package com.heima.example1;

import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

public class Server {
    public static void main(String[] args) throws Exception{

        ServerSocket serverSocket = new ServerSocket(8888);

        Socket socket = serverSocket.accept();

        InputStreamReader inputStreamReader = new InputStreamReader(socket.getInputStream());

        int b;
        /**
         *  如果客户端没有执行 shutdownOutput 方法,服务端会一直卡在 read 方法
         */
        while ((b = inputStreamReader.read()) != -1) {
            System.out.print((char) b);
        }

        System.out.println();
        System.out.println("b is "+ b);
        System.out.println("--------程序即将结束--------"+new Date().getTime());

        socket.close();
        serverSocket.close();

    }
}
